<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">




<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
  </script>






<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />



  <link rel="icon" type="image/png" sizes="32x32" href="/favicon.ico?v=5.1.4">







  <meta name="keywords" content="iOS," />





  <link rel="alternate" href="/atom.xml" title="Swift社区" type="application/atom+xml" />






<meta name="description" content="前言SwiftUI 的各种堆栈是许多框架中最基本的布局工具，能够让我们定义组视图，这些组视图可以按照水平、垂直或覆盖视图对齐。 当涉及到水平和垂直的变体时( HStack 和 VStack )，我们需要在这两者之间动态的切换。举个例子，假如我们正在构建一个 app 其中包含 LoginActionsView ，一个让用户登录时在列表中选择操作的类：">
<meta name="keywords" content="iOS">
<meta property="og:type" content="article">
<meta property="og:title" content="SwiftUI 之 HStack 和 VStack 的切换">
<meta property="og:url" content="https://fanbaoying.github.io/SwiftUI-之-HStack-和-VStack-的切换/index.html">
<meta property="og:site_name" content="Swift社区">
<meta property="og:description" content="前言SwiftUI 的各种堆栈是许多框架中最基本的布局工具，能够让我们定义组视图，这些组视图可以按照水平、垂直或覆盖视图对齐。 当涉及到水平和垂直的变体时( HStack 和 VStack )，我们需要在这两者之间动态的切换。举个例子，假如我们正在构建一个 app 其中包含 LoginActionsView ，一个让用户登录时在列表中选择操作的类：">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2022-09-26T03:58:04.704Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="SwiftUI 之 HStack 和 VStack 的切换">
<meta name="twitter:description" content="前言SwiftUI 的各种堆栈是许多框架中最基本的布局工具，能够让我们定义组视图，这些组视图可以按照水平、垂直或覆盖视图对齐。 当涉及到水平和垂直的变体时( HStack 和 VStack )，我们需要在这两者之间动态的切换。举个例子，假如我们正在构建一个 app 其中包含 LoginActionsView ，一个让用户登录时在列表中选择操作的类：">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://fanbaoying.github.io/SwiftUI-之-HStack-和-VStack-的切换/"/>





  <title>SwiftUI 之 HStack 和 VStack 的切换 | Swift社区</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    
    <a href="https://github.com/SwiftCommunityRes" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Swift社区</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">做最好的 Swift 社区</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://fanbaoying.github.io/SwiftUI-之-HStack-和-VStack-的切换/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Swift社区">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://avatars.githubusercontent.com/u/84354365?v=4">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Swift社区">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">SwiftUI 之 HStack 和 VStack 的切换</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2022-09-26T11:56:25+08:00">
                2022-09-26
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/SwiftUI/" itemprop="url" rel="index">
                    <span itemprop="name">SwiftUI</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>

                <!-- 
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                -->
                <span title="字数统计">
                  数字统计 2,319字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>

                <!-- 
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                --> 

                <span title="阅读时长">
                  阅读时长 9分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p><code>SwiftUI</code> 的各种堆栈是许多框架中最基本的布局工具，能够让我们定义组视图，这些组视图可以按照水平、垂直或覆盖视图对齐。</p>
<p>当涉及到水平和垂直的变体时( <code>HStack</code> 和 <code>VStack</code> )，我们需要在这两者之间动态的切换。举个例子，假如我们正在构建一个 <code>app</code> 其中包含 <code>LoginActionsView</code> ，一个让用户登录时在列表中选择操作的类：</p>
<a id="more"></a>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">LoginActionsView</span>: <span class="title">View</span> </span>&#123;</span><br><span class="line">    ...</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> body: some <span class="type">View</span> &#123;</span><br><span class="line">        <span class="type">VStack</span> &#123;</span><br><span class="line">            <span class="type">Button</span>(<span class="string">"Login"</span>) &#123; ... &#125;</span><br><span class="line">            <span class="type">Button</span>(<span class="string">"Reset password"</span>) &#123; ... &#125;</span><br><span class="line">            <span class="type">Button</span>(<span class="string">"Create account"</span>) &#123; ... &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        .buttonStyle(<span class="type">ActionButtonStyle</span>())</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">ActionButtonStyle</span>: <span class="title">ButtonStyle</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">func</span> <span class="title">makeBody</span><span class="params">(configuration: Configuration)</span></span> -&gt; some <span class="type">View</span> &#123;</span><br><span class="line">        configuration.label</span><br><span class="line">            .fixedSize()</span><br><span class="line">            .frame(maxWidth: .infinity)</span><br><span class="line">            .padding()</span><br><span class="line">            .foregroundColor(.white)</span><br><span class="line">            .background(<span class="type">Color</span>.blue)</span><br><span class="line">            .cornerRadius(<span class="number">10</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>以上代码中，我们用到了 <code>fixedSize</code> 防止按钮文本被截断，这仅是在我们确信给定的内容视图不会比视图本身更大的情况。想了解更多信息，可以查看我的文章 -  <a href="https://www.swiftbysundell.com/articles/swiftui-layout-system-guide-part-3/#fixed-dimensions" target="_blank" rel="noopener">SwiftUI 布局系统第三章</a></p>
</blockquote>
<p>目前，我们的按钮是垂直排列的，并且填满了水平线上的可用空间（你可以用以上示例代码预览按钮的样子），虽然这在竖向的 iPhone 上看起来很好，但假设我们现在想要在横向模式下让 <code>UI</code> 横向排列。</p>
<h2 id="GeometryReader-能实现吗？"><a href="#GeometryReader-能实现吗？" class="headerlink" title="GeometryReader 能实现吗？"></a>GeometryReader 能实现吗？</h2><p>一种方式是用 <code>GeometryReader</code> 测量当前可用空间，并根据宽度是否大于其高度，可以选择使用 <code>HStack</code> 或  <code>VStack</code> 来渲染内容。</p>
<p>虽然可以在 <code>LoginActionsView</code> 中放入该逻辑，但我们希望以后能复用代码，因此需要重新创建一个专门的视图，作为一个独立的组件来实现动态堆栈的切换逻辑。</p>
<p>为了使代码可用性更高，我们不会硬编码让两个堆栈变体使用对齐或间距什么的。相反，让我们像 <code>SwiftUI</code> 一样，对这些属性参数化，同时设定框架所使用的默认值 — 就像这样：</p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">DynamicStack</span>&lt;<span class="title">Content</span>: <span class="title">View</span>&gt;: <span class="title">View</span> </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> horizontalAlignment = <span class="type">HorizontalAlignment</span>.center</span><br><span class="line"><span class="keyword">var</span> verticalAlignment = <span class="type">VerticalAlignment</span>.center</span><br><span class="line"><span class="keyword">var</span> spacing: <span class="type">CGFloat</span>?</span><br><span class="line">    @<span class="type">ViewBuilder</span> <span class="keyword">var</span> content: () -&gt; <span class="type">Content</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> body: some <span class="type">View</span> &#123;</span><br><span class="line">        <span class="type">GeometryReader</span> &#123; proxy <span class="keyword">in</span></span><br><span class="line">            <span class="type">Group</span> &#123;</span><br><span class="line">                <span class="keyword">if</span> proxy.size.width &gt; proxy.size.height &#123;</span><br><span class="line">                    <span class="type">HStack</span>(</span><br><span class="line">                        alignment: verticalAlignment,</span><br><span class="line">                        spacing: spacing,</span><br><span class="line">                        content: content</span><br><span class="line">                    )</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    <span class="type">VStack</span>(</span><br><span class="line">                        alignment: horizontalAlignment,</span><br><span class="line">                        spacing: spacing,</span><br><span class="line">                        content: content</span><br><span class="line">                    )</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>由于我们使新的 <code>DynamicStack</code> 使用了与 <code>HStack</code>  和 <code>VStack</code> 相同的 <code>API</code> ，现在可以在 <code>LoginActionsView</code> 中直接将以前的 <code>VStack</code> 换成新的自定义的实例：</p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">LoginActionsView</span>: <span class="title">View</span> </span>&#123;</span><br><span class="line">    ...</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> body: some <span class="type">View</span> &#123;</span><br><span class="line">        <span class="type">DynamicStack</span> &#123;</span><br><span class="line">            <span class="type">Button</span>(<span class="string">"Login"</span>) &#123; ... &#125;</span><br><span class="line">            <span class="type">Button</span>(<span class="string">"Reset password"</span>) &#123; ... &#125;</span><br><span class="line">            <span class="type">Button</span>(<span class="string">"Create account"</span>) &#123; ... &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        .buttonStyle(<span class="type">ActionButtonStyle</span>())</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>优秀！然而，就像上面的代码展示的那样，使用 <code>GeometeryReader</code> 来展示动态切换有一个相当明显的缺点，在几何图形阅读器中总是会填充水平和垂直方向的所有可用空间（以便测量实际空间）。在我们的例子中，<code>LoginActionsView</code> 不再只是水平方向的排列，它现在也能移动到屏幕的顶部。</p>
<p>虽然我们也有很多方法能解决这些问题（例如使用类似在<a href="https://swiftbysundell.com/questions/syncing-the-width-or-height-of-two-swiftui-views/" target="_blank" rel="noopener">这篇 Q&amp;A </a>中用来使多个视图具有相同宽度和高度的技术），但真正的问题是当我们要动态的确定方向时，测量可用空间是否是一个好的方法。</p>
<h2 id="一个使用尺寸类的例子"><a href="#一个使用尺寸类的例子" class="headerlink" title="一个使用尺寸类的例子"></a>一个使用尺寸类的例子</h2><p>相反，让我们使用 <code>Apple</code> 的尺寸类系统来决定 <code>DynamicStack</code> 应该在底层使用 <code>HStack</code> 还是 <code>VStack</code> 。这样做的好处不仅仅是在引入 <code>GeometeryReader</code> 之前保留同样紧凑的布局，并且会使 <code>DynamicStack</code> 在开始的时候以一种和系统组件类似的方式在所有设备和方向上构建。</p>
<p>为了观察当前水平方向的尺寸，我们需要用到 <a href="https://swiftbysundell.com/articles/swiftui-state-management-guide/#observing-and-modifying-the-environment" target="_blank" rel="noopener">SwiftUI 环境系统</a>  —  通过在 <code>DynamicStack</code> 中声明 <code>@Environment</code> - 标记属性（带有  <code>horizontalSizeClass</code> <a href="https://swiftbysundell.com/articles/the-power-of-key-paths-in-swift/" target="_blank" rel="noopener">关键路径</a>），将会使我们在视图内容中切换到当前 <code>sizeClass</code> 的值：</p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">DynamicStack</span>&lt;<span class="title">Content</span>: <span class="title">View</span>&gt;: <span class="title">View</span> </span>&#123;</span><br><span class="line">    ...</span><br><span class="line">    @<span class="type">Environment</span>(\.horizontalSizeClass) <span class="keyword">private</span> <span class="keyword">var</span> sizeClass</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> body: some <span class="type">View</span> &#123;</span><br><span class="line">        <span class="keyword">switch</span> sizeClass &#123;</span><br><span class="line">        <span class="keyword">case</span> .regular:</span><br><span class="line">            hStack</span><br><span class="line">        <span class="keyword">case</span> .compact, .<span class="keyword">none</span>:</span><br><span class="line">            vStack</span><br><span class="line">        @unknown <span class="keyword">default</span>:</span><br><span class="line">            vStack</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">private</span> <span class="class"><span class="keyword">extension</span> <span class="title">DynamicStack</span> </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> hStack: some <span class="type">View</span> &#123;</span><br><span class="line">        <span class="type">HStack</span>(</span><br><span class="line">            alignment: verticalAlignment,</span><br><span class="line">            spacing: spacing,</span><br><span class="line">            content: content</span><br><span class="line">        )</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> vStack: some <span class="type">View</span> &#123;</span><br><span class="line">        <span class="type">VStack</span>(</span><br><span class="line">            alignment: horizontalAlignment,</span><br><span class="line">            spacing: spacing,</span><br><span class="line">            content: content</span><br><span class="line">        )</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>经过以上操作，<code>LoginActionsView</code> 将可以在常规的尺寸渲染时动态切换成水平布局（例如在大尺寸的 <code>iPhone</code> 使用横屏，或者全屏 <code>iPad</code> 上的任一方向），而其它所有尺寸的配置使用垂直布局。所有这些仍然使用紧凑垂直布局，它使用的空间不超过渲染其内容所需的空间。</p>
<h2 id="使用布局协议"><a href="#使用布局协议" class="headerlink" title="使用布局协议"></a>使用布局协议</h2><p>虽然我们最后已经用了非常棒的解决方案，可以在所有支持 <code>SwiftUI</code>  的 <code>iOS</code> 版本中使用，但也让我们来探索一下在 <code>iOS 16</code> 中引入的一些新的布局工具（在写这篇文章时，它作为 <code>Xcode 14</code> 的一部分仍在测试阶段） </p>
<p>其中一个工具是新的 <code>Layout</code> 协议，它既能让我们创建完整的自定义布局，直接集成到 <code>SwiftUI</code>  的布局系统中，同时也提供给我们一种更丝滑更动画的方式在各种布局之间动态切换 。</p>
<p>这都是因为事实证明 <code>Layout</code> 不仅仅是我们第三方开发者的 <code>API</code> ，<code>Apple</code> 也让 <code>SwiftUI</code> 自己的布局容器使用这个新协议 。所以，与其直接使用 <code>HStack</code> 和 <code>VStack</code> 作为容器视图，不如将它们作为符合 <code>Layout</code> 的实例，使用 <code>AnyLayout</code> 类型进行包装 — 就像这样：</p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="class"><span class="keyword">extension</span> <span class="title">DynamicStack</span> </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> currentLayout: <span class="type">AnyLayout</span> &#123;</span><br><span class="line">        <span class="keyword">switch</span> sizeClass &#123;</span><br><span class="line">        <span class="keyword">case</span> .regular, .<span class="keyword">none</span>:</span><br><span class="line">            <span class="keyword">return</span> horizontalLayout</span><br><span class="line">        <span class="keyword">case</span> .compact:</span><br><span class="line">            <span class="keyword">return</span> verticalLayout</span><br><span class="line">        @unknown <span class="keyword">default</span>:</span><br><span class="line">            <span class="keyword">return</span> verticalLayout</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> horizontalLayout: <span class="type">AnyLayout</span> &#123;</span><br><span class="line">        <span class="type">AnyLayout</span>(<span class="type">HStack</span>(</span><br><span class="line">            alignment: verticalAlignment,</span><br><span class="line">            spacing: spacing</span><br><span class="line">        ))</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> verticalLayout: <span class="type">AnyLayout</span> &#123;</span><br><span class="line">        <span class="type">AnyLayout</span>(<span class="type">VStack</span>(</span><br><span class="line">            alignment: horizontalAlignment,</span><br><span class="line">            spacing: spacing</span><br><span class="line">        ))</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>以上的操作是可行的，因为当 <code>HStack</code> 和 <code>VStack</code> 的内容类型是 <code>EmptyView</code> 时，它们都符合新的 <code>Layout</code> 协议（当内容为空时就是这种情况），让我们来看一下<code>SwiftUI</code>  的 公共接口</p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">DynamicStack</span>&lt;<span class="title">Content</span>: <span class="title">View</span>&gt;: <span class="title">View</span> </span>&#123;</span><br><span class="line">    ...</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> body: some <span class="type">View</span> &#123;</span><br><span class="line">        currentLayout(content)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>  注意：由于回归， <code>Xcode 14 beta 3</code> 中省略了以上条件的一致性，根据 <code>SwiftUI</code> 团队的 <a href="https://twitter.com/ricketson_/status/1544784314453282817" target="_blank" rel="noopener">Matt Ricketson 的说法</a>，可以直接使用底层的 <code>_HStackLayout</code> 和 <code>_VStackLayout</code> 类型作为临时的解决方法。并希望能在未来测试版本中修复。    </p>
</blockquote>
<p>现在我们能通过使用新的 <code>currentLayout</code> 解决使用什么布局，现在我们来更新 <code>body</code> 的实现，简单调用从该属性返回的 <code>AnyLayout</code> ，就像函数一样 — 像这样：</p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">DynamicStack</span>&lt;<span class="title">Content</span>: <span class="title">View</span>&gt;: <span class="title">View</span> </span>&#123;</span><br><span class="line">    ...</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> body: some <span class="type">View</span> &#123;</span><br><span class="line">        currentLayout(content)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>  我们之所以能像一个函数一样调用布局方法（尽管它实际上是一个结构）是因为 <code>Layout</code> 协议使用了 <code>Swift</code> <a href="https://swiftbysundell.com/articles/exploring-swift-5-2s-new-functional-features/#calling-types-as-functions" target="_blank" rel="noopener">”像函数一样调用“ 的特性</a></p>
</blockquote>
<p>那么我们之前的方案和上面基于布局的方案有什么区别呢？关键的区别在于（除了后者需要 <code>iOS 16</code> ）切换布局可以保留正在渲染的底层视图的标识，而在 <code>HStack</code> 和 <code>VStack</code> 之间切换就不会这样。这样做会令动画更流畅，例如在切换设备方向时，我们也有可能在执行此类更改时获得小幅的性能提升（因为 <code>SwiftUI</code> 总是在其视图层次结构为静态时尽可能表现最佳）</p>
<h2 id="选择合适的视图"><a href="#选择合适的视图" class="headerlink" title="选择合适的视图"></a>选择合适的视图</h2><p>但我们还没有结束，因为 <code>iOS 16</code> 也给了我们其他有趣的新的布局工具，它有可能也能用于实现 <code>DynamicStack</code>  — 一种全新的视图类型，名字叫做 <code>ViewThatFits</code> 。就像字面意思一样，这种新的容器将会在我们初始化时传递的候选列表中，基于当前上下文挑选出最优视图。</p>
<p>在我们的例子中，这意味着我们能同时把 <code>HStack</code> 和 <code>VStack</code> 传递给它，并且代表我们在它们中间自动切换。</p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">DynamicStack</span>&lt;<span class="title">Content</span>: <span class="title">View</span>&gt;: <span class="title">View</span> </span>&#123;</span><br><span class="line">    ...</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> body: some <span class="type">View</span> &#123;</span><br><span class="line">        <span class="type">ViewThatFits</span> &#123;</span><br><span class="line">            <span class="type">HStack</span>(</span><br><span class="line">                alignment: verticalAlignment,</span><br><span class="line">                spacing: spacing,</span><br><span class="line">                content: content</span><br><span class="line">            )</span><br><span class="line"></span><br><span class="line">            <span class="type">VStack</span>(</span><br><span class="line">                alignment: horizontalAlignment,</span><br><span class="line">                spacing: spacing,</span><br><span class="line">                content: content</span><br><span class="line">            )</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>注意：在这种情况下，我们首先放置 <code>HStack</code> 是很重要的，因为 <code>VStack</code> 可能总是合适的，即使在我们希望布局是横向的情况下（例如 <code>iPad</code> 的全屏模式）。同样重要的是要指出，上述基于 <code>ViewThatFits</code> 的技术将会始终尝试 <code>HStack</code> ，即使在用紧凑尺寸渲染布局时也是如此，只有在 <code>HStack</code> 不适合时才会选择基于<code>VStack</code> 的布局。  </p>
<h2 id="结语"><a href="#结语" class="headerlink" title="结语"></a>结语</h2><p>以上就是通过四种不同的方式实现 <code>DynamicStack</code> 视图，它可以根据当前内容在 <code>HStack</code> 和 <code>VStack</code> 之间动态切换。</p>
<h2 id="关于我们"><a href="#关于我们" class="headerlink" title="关于我们"></a>关于我们</h2><p>我们是由 Swift 爱好者共同维护，我们会分享以 Swift 实战、SwiftUI、Swift 基础为核心的技术内容，也整理收集优秀的学习资料。</p>
<p>后续还会翻译大量资料到我们公众号，有感兴趣的朋友，可以加入我们。</p>

      
    </div>
    
    
    
    

    
      <div>
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

      </div>
    


    
      <div>
        
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

  <!-- JS库 sweetalert 可修改路径 -->
  <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
  <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  <p><span>本文标题:</span><a href="/SwiftUI-之-HStack-和-VStack-的切换/">SwiftUI 之 HStack 和 VStack 的切换</a></p>
  <p><span>文章作者:</span><a href="/" title="访问 Swift社区 的个人博客">Swift社区</a></p>
  <p><span>发布时间:</span>2022年09月26日 - 11:09</p>
  <p><span>最后更新:</span>2022年09月26日 - 11:09</p>
  <p><span>原始链接:</span><a href="/SwiftUI-之-HStack-和-VStack-的切换/" title="SwiftUI 之 HStack 和 VStack 的切换">https://fanbaoying.github.io/SwiftUI-之-HStack-和-VStack-的切换/</a>
    <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="https://fanbaoying.github.io/SwiftUI-之-HStack-和-VStack-的切换/"  aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
      $(".fa-clipboard").click(function(){
      clipboard.on('success', function(){
        swal({   
          title: "",   
          text: '复制成功',
          icon: "success", 
          showConfirmButton: true
          });
        });
    });  
</script>

      </div>
    


    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechat.png" alt="Swift社区 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.png" alt="Swift社区 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/iOS/" rel="tag"><i class="fa fa-tag"></i> iOS</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/第三方库并不是必须的/" rel="next" title="第三方库并不是必须的">
                <i class="fa fa-chevron-left"></i> 第三方库并不是必须的
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/实现模块化应用的本地化/" rel="prev" title="实现模块化应用的本地化">
                实现模块化应用的本地化 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
<span class="jiathis_txt">分享到：</span>
<a class="jiathis_button_fav">收藏夹</a>
<a class="jiathis_button_copy">复制网址</a>
<a class="jiathis_button_email">邮件</a>
<a class="jiathis_button_weixin">微信</a>
<a class="jiathis_button_qzone">QQ空间</a>
<a class="jiathis_button_tqq">腾讯微博</a>
<a class="jiathis_button_douban">豆瓣</a>
<a class="jiathis_button_share">一键分享</a>

<a href="http://www.jiathis.com/share?uid=2140465" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank">更多</a>
<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
var jiathis_config={
  data_track_clickback:true,
  summary:"",
  shortUrl:false,
  hideMore:false
}
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=" charset="utf-8"></script>
<!-- JiaThis Button END -->
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="https://avatars.githubusercontent.com/u/84354365?v=4"
                alt="Swift社区" />
            
              <p class="site-author-name" itemprop="name">Swift社区</p>
              <p class="site-description motion-element" itemprop="description">我们的使命是做一个最专业最权威的 Swift 中文社区，我们的愿景是希望更多的人学习和使用Swift。我们会分享以 Swift 实战、SwiftUI、Swift 基础为核心的技术干货，不忘初心，牢记使命。</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">187</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">19</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://blog.csdn.net/qq_36478920" target="_blank" title="CSDN">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>CSDN</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/5a30d987f265da430d580126" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-spinner"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/fanbaoying" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/swift-community" target="_blank" title="知乎">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>知乎</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/u/7711465033" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-weibo"></i>微博</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzAxNzgzNTgwMw==&action=getalbum&album_id=2024314764775981057" target="_blank" title="公众号">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>公众号</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://github.com/SwiftCommunityRes/SwiftWeekly" title="SwiftWeekly" target="_blank">SwiftWeekly</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://github.com/SwiftCommunityRes/article-ios" title="Article-ios" target="_blank">Article-ios</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://github.com/SwiftCommunityRes/SwiftUI-Book" title="SwiftUI-Book" target="_blank">SwiftUI-Book</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#GeometryReader-能实现吗？"><span class="nav-number">2.</span> <span class="nav-text">GeometryReader 能实现吗？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#一个使用尺寸类的例子"><span class="nav-number">3.</span> <span class="nav-text">一个使用尺寸类的例子</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用布局协议"><span class="nav-number">4.</span> <span class="nav-text">使用布局协议</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#选择合适的视图"><span class="nav-number">5.</span> <span class="nav-text">选择合适的视图</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#结语"><span class="nav-number">6.</span> <span class="nav-text">结语</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#关于我们"><span class="nav-number">7.</span> <span class="nav-text">关于我们</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Swift社区</span>

  
</div>

<!-- 
<div class="powered-by">
  <i class="fa fa-user-md">
  </i>
  <span id="busuanzi_container_site_uv">
    已有<span id="busuanzi_value_site_uv"></span>人来访
  </span>

</div>


  <span class="post-meta-divider">|</span>


<div class="powered-by">
  <i class="fa fa-eye"></i>
  <span id="busuanzi_container_site_pv">
      访问量<span id="busuanzi_value_site_pv"></span>次
  </span>
</div>



  <span class="post-meta-divider">|</span>


-->

<div class="theme-info">
  <i class="fa fa-pencil"></i>
  <span class="post-count">博客全站共361.6k字</span>
</div>


<!-- 
  <span class="post-meta-divider">|</span>



  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>



-->

        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
